import type { ColumnsType } from 'antd/es/table';
import { menuTypes, isSuperTypes } from './dictionary'
import { Button, Space } from 'antd';
import { IMenu } from './types';
import IconSvg from "@/components/iconSvg";

export const columns = (edit: (info: IMenu,type:string) => void, remove: (info: IMenu) => void):ColumnsType<object> => {
    return [
        {
            title: '名称',
            dataIndex: 'menuName',
            key: 'menuName',
        },
        {
            title: '图标',
            dataIndex: 'icon',
            render:(value, record, index)=>{
                return <IconSvg name={value} />
            },
            key: 'icon',
            width: 80
        },
        {
            title: '排序',
            dataIndex: 'orderNum',
            key: 'orderNum',
            ellipsis: true,
            width: 60
        },
        {
            title: '类型',
            dataIndex: 'menuType',
            render: (text: any) => {
                let info = menuTypes.find(item => item.value == text)
                return info?.label;
            },
            align: 'center',
            width: 60
        },
        {
            title: '显示菜单',
            dataIndex: 'extendone',
            render: (text: any) => `${text == 'true' ? '隐藏' : '显示'}`,
            width: 80
        },
        {
            title: '开放租户',
            key: 'isUniq',
            dataIndex: 'isUniq',
            render: (text: any) => {
                let info = isSuperTypes.find(item => item.value == text)
                return info?.label;
            },
            ellipsis: true,
            width: 80
        },
        {
            title: '路径',
            key: 'path',
            render: (text: any) => {
                return text.menuType != 'F' && text.path
            },
            ellipsis: true,

        },
        {
            title: '权限标识',
            key: 'permission',
            render: (text: any) => {
                return text.menuType == 'F' && text.path
            },
            ellipsis: true,
            width: 100
        },
        {
            title: '操作',
            width: 180,
            fixed: 'right',
            render: (text: any, row: IMenu, index: number) => (
                <Space>
                    <Button type="default" size='small' onClick={() => edit(row,'edit')}>编辑</Button>
                    <Button type="primary" size='small' onClick={() => edit(row,'add')}>新增</Button>
                    <Button type="primary" size='small' danger onClick={() => remove(row)}>删除</Button>
                </Space>
            )
        }
    ];
}